package com.wenjh.jdmzt.android.synctask;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPool extends ThreadPoolExecutor {

	/** 核心线程个数，一直保留 */
	private final static int SIZE_POOL_CORE = 2;
	/** 最多线程数 */
	private final static int SIZE_POLL_MAX = 10;
	/** 线程空闲5分钟后回收 */
	private final static int TIME_KEEP_ALIVE = 5;
	/** 时间单位:分钟 */
	private final static TimeUnit TIME_UNIT = TimeUnit.SECONDS;

	private ThreadPool() {
		super(SIZE_POOL_CORE, SIZE_POLL_MAX, TIME_KEEP_ALIVE, TIME_UNIT, new LinkedBlockingQueue<Runnable>(), new ThreadPoolExecutor.DiscardOldestPolicy());
	}


	public ThreadPool(int min, int max) {
		super(min, max, TIME_KEEP_ALIVE, TIME_UNIT, new LinkedBlockingQueue<Runnable>(), new ThreadPoolExecutor.DiscardOldestPolicy());
		
	}
	
	public ThreadPool(int min, int max, RejectedExecutionHandler executionHandler) {
		super(min, max, TIME_KEEP_ALIVE, TIME_UNIT, new LinkedBlockingQueue<Runnable>(), executionHandler);
		
	}

	public static ThreadPoolExecutor getSingleThreadPool() {
		return new ThreadPool(1, 1);
	}
}
